<template>
  <!-- 人员信息维护-->
  <div>
    <!-- 搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="3"
      labelWidth="100"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchParams"
      :isSelectColumn="isSelectColumn"
      :params="flterValue"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-download" >下载</el-button>
      </template>
    </FilterTable>
    <!-- 经销商弹窗 -->
    <BaseDialog
      title="人员信息维护"
      :visible.sync="visible"
      width="800px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <addDialog  v-model="initData" @close="dialogClose" />
    </BaseDialog>
    <!-- 经销商弹窗 -->
    <BaseDialog
      title="经销商查询"
      :visible.sync="visibleDealer"
      width="1000px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <dealer-madal  ref='addDialogRef'  @close="closeDealer" />
    </BaseDialog>
  </div>
</template>
<script>
import dealerMadal from '../../../customerManage/clue/areaBossPush/dealerMadal';
import addDialog from '../personnelInfoMaintain/addDialog';
import { dictionary } from '@/utils/dictMixin';
export default {
  components: {
    addDialog,
    dealerMadal
  },
  mixins: [dictionary],
  data() {
    return {
      visible: false,
      visibleDealer: false,
      isSelectColumn: false,
      initData: {},
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: null //ipa 接口
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '部门名称', fieldName: 'field1', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '员工姓名', fieldName: 'field3', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '员工编号', fieldName: 'field7', placeholder: '请输入', initialValue: '' },
        { type: 'SELECT', label: '在职状态', fieldName: 'field2', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1008') },
        { type: 'SELECT', label: '数据来源', fieldName: 'field51', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1008') },
        {
          type: 'INPUT',
          label: '经销商',
          fieldName: 'dealer',
          placeholder: '请选择',
          initialValue: '',
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={() => this.dealerHandle()}></el-button>;
          }
        },
        { type: 'SELECT', label: '岗位名称', fieldName: 'field5', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1008') }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.flterValue = val;
      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.dialogHandle(props.row, 'show')}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        { title: '数据来源', dataIndex: 'field0', sorter: true },
        { title: '经销商', dataIndex: 'field1', sorter: true },
        { title: '员工编号', dataIndex: 'field11', sorter: true },
        { title: '员工姓名', dataIndex: 'field12', sorter: true },
        {
          title: '性别',
          dataIndex: 'field2',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }
        },
        { title: '身份证号码', dataIndex: 'field3', sorter: true },
        { title: '部门名称', dataIndex: 'field4', sorter: true },
        { title: '岗位名称', dataIndex: 'field51', sorter: true },
        { title: '手机', dataIndex: 'field52', sorter: true },
        {
          title: '在职状态',
          dataIndex: 'field53',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }
        }
      ];
    },
    // 经销商打开窗口 -传数据
    dealerHandle() {
      this.visibleDealer = true;
    },
    // 经销商关闭窗口 -返回数据
    closeDealer(data) {
      //返回数据逻辑自己写
      this.topFilterInit[5].initialValue = '选择经销商';
      this.visibleDealer = data.visible; //关闭弹窗
    },
    //详情
    dialogHandle(row, tpye) {
      this.visible = true;
      const pram = {
        type: tpye,
        id: 1001
      };
      this.initData=pram
    },
    //关闭详情
    dialogClose(data) {
      this.visible = false;
      // if (data.type === 'refresh') {
      //   // 重新加载
      //   this.fetchParams = { ...this.fetchParams };
      // }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    }
  }
};
</script>

<style lang="less" scoped>
</style>
